package org.zhiyootech.repository;

import io.quarkus.hibernate.orm.panache.PanacheRepository;
import io.quarkus.panache.common.Parameters;
import org.zhiyootech.entity.UserInfo;

import javax.enterprise.context.ApplicationScoped;

@ApplicationScoped
public class UserInfoRepository implements PanacheRepository<UserInfo> {

    /**
     * 查询有效记录
     *
     * @param cstId
     * @return
     */
    public UserInfo findByCstId(Long cstId) {
        return find("cstId = :cstId and isDel = :isDel",
                Parameters.with("cstId", cstId)
                        .and("isDel", 0)
        )
                .firstResult();
    }

    /**
     * 根据openID 查询有效记录
     *
     * @param openId
     * @return UserInfo
     */
    public UserInfo findByOpenId(String openId) {
        return find("openId = :openId and isDel = :isDel",
                Parameters.with("openId", openId)
                        .and("isDel", 0)
        ).firstResult();
    }

}

